package com.wx.mall.user.controller;


import com.wx.mall.common.utils.DataResult;
import com.wx.mall.user.entity.Ms;
import com.wx.mall.user.service.IMsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 会员等级设置表 前端控制器
 * </p>
 *
 * @author j
 * @since 2020-03-18
 */
@Api(tags = "MsController",description = "会员等级设置")
@RestController
@RequestMapping("/ms")
@Slf4j
public class MsController {
    @Resource
    IMsService service;

    @ApiOperation("查询出所有信息")
    @GetMapping("/listAll")
    public DataResult getListAll(){
        List<Ms> list=service.list();
        return DataResult.success(list);

    };
    @ApiOperation("根据Id查询信息s")
    @GetMapping("/listAllById")
    public DataResult getListById(Integer msId){
       Ms list=service.getById(msId);
        return DataResult.success(list);

    };
    @ApiOperation("根据Id修改数据")
    @PutMapping("/updateListById")
    public DataResult setListById(Ms ms){
        int success=service.setListById(ms);

        return success==1?DataResult.success():DataResult.getResult(1,"修改失败");

    };
    @ApiOperation("添加一条数据")
    @PostMapping("/addList")
    public DataResult addList(Ms ms){
        boolean success=service.save(ms);


        return success?DataResult.success():DataResult.getResult(1,"添加失败");

    };

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除数据")
    public DataResult deleteById(@PathVariable("id") @NotNull(message = "id不能为空") Integer msId) {
        boolean sucess=service.removeById(msId);
        return sucess?DataResult.success():DataResult.getResult(1,"删除失败");
    }

}

